package com.fc.test.service;

import java.util.HashMap;
import java.util.List;

import com.fc.test.mapper.auto.TAbbRenzhengMapper;
import com.fc.test.model.auto.*;
import org.apache.shiro.SecurityUtils;
import java.util.Map;

import com.fc.test.mapper.auto.TAbbRenzhengMapper;
import com.fc.test.model.auto.TAbbRenzheng;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.TAbbGoodsMapper;
import com.fc.test.model.auto.TAbbGoods;
import com.fc.test.model.auto.TAbbGoodsExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;

/**
 * Service
* @Title: TAbbGoodsService.java 
* @Package com.fc.test.entity 
* @author fuce
* @email 87766867@qq.com
* @date 2019-08-22 18:34:02  
 */
@Service
public class TAbbGoodsService implements BaseService<TAbbGoods, TAbbGoodsExample>{
	@Autowired
	private TAbbGoodsMapper tAbbGoodsMapper;
	@Autowired
	private TAbbRenzhengMapper tAbbRenzhengMapper;

	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<TAbbGoods> list(Tablepar tablepar,String name,String shopname,int type){
	        TAbbGoodsExample testExample=new TAbbGoodsExample();
	        //testExample.setOrderByClause("id ASC");
		    testExample.setOrderByClause("updatetime DESC");
		 TAbbGoodsExample.Criteria criteria=testExample.createCriteria();
	        if(name!=null&&!"".equals(name)){
				criteria.andGoodsnameLike("%"+name+"%");
	        }
			 if(shopname!=null&&!"".equals(shopname)){
				 criteria.andShopnameLike("%"+shopname+"%");
			 }
		    criteria.andTypeEqualTo(type);
	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<TAbbGoods> list= tAbbGoodsMapper.selectByExample(testExample);
	        PageInfo<TAbbGoods> pageInfo = new PageInfo<TAbbGoods>(list);
	        return  pageInfo;
	 }
	public PageInfo<TAbbGoods> sjlist(Tablepar tablepar, String searchTxt, int type) {
		TsysUser user= (TsysUser) SecurityUtils.getSubject().getPrincipal();
		TAbbRenzhengExample testExample1=new TAbbRenzhengExample();
		testExample1.createCriteria().andLoginusernameEqualTo(user.getUsername());
		List<TAbbRenzheng> list1= tAbbRenzhengMapper.selectByExample(testExample1);
		TAbbRenzheng tAbbRenzheng=list1.get(0);


		TAbbGoodsExample testExample=new TAbbGoodsExample();
		//testExample.setOrderByClause("id ASC");
		testExample.setOrderByClause("updatetime DESC");
		TAbbGoodsExample.Criteria criteria=testExample.createCriteria();
		if(searchTxt!=null&&!"".equals(searchTxt)){
			criteria.andGoodsnameLike("%"+searchTxt+"%");
		}
		criteria.andTypeEqualTo(type);
		criteria.andShopidEqualTo(tAbbRenzheng.getId());
		PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
		List<TAbbGoods> list= tAbbGoodsMapper.selectByExample(testExample);
		PageInfo<TAbbGoods> pageInfo = new PageInfo<TAbbGoods>(list);
		return  pageInfo;
	}
	@Override
	public int deleteByPrimaryKey(String ids) {
		List<String> lista=Convert.toListStrArray(ids);
		TAbbGoodsExample example=new TAbbGoodsExample();
		example.createCriteria().andIdIn(lista);
		return tAbbGoodsMapper.deleteByExample(example);
	}


	@Override
	public TAbbGoods selectByPrimaryKey(String id) {

		return tAbbGoodsMapper.selectByPrimaryKey(id);
	}


	@Override
	public int updateByPrimaryKeySelective(TAbbGoods record) {
		return tAbbGoodsMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 添加
	 */
	@Override
	public int insertSelective(TAbbGoods record) {
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
		return tAbbGoodsMapper.insertSelective(record);
	}










	@Override
	public int updateByExampleSelective(TAbbGoods record, TAbbGoodsExample example) {

		return tAbbGoodsMapper.updateByExampleSelective(record, example);
	}


	@Override
	public int updateByExample(TAbbGoods record, TAbbGoodsExample example) {

		return tAbbGoodsMapper.updateByExample(record, example);
	}

	@Override
	public List<TAbbGoods> selectByExample(TAbbGoodsExample example) {

		return tAbbGoodsMapper.selectByExample(example);
	}


	@Override
	public long countByExample(TAbbGoodsExample example) {

		return tAbbGoodsMapper.countByExample(example);
	}


	@Override
	public int deleteByExample(TAbbGoodsExample example) {

		return tAbbGoodsMapper.deleteByExample(example);
	}


	public List<TAbbGoods> getCuxiaoBannerList(){
		List<TAbbGoods> list = tAbbGoodsMapper.getCuxiaoBannerList();
		return list;
	}


	public List<TAbbGoods> getCuxiaoGoodsList(String area,int page){
		Map<String,Object> paramMap = new HashMap<>();
		if(null!=area&&"包邮区".equals(area)){
			paramMap.put("isbaoyou",1);
		}else{
			paramMap.put("area",area);
		}
		paramMap.put("page",page);
		List<TAbbGoods> list = tAbbGoodsMapper.getCuxiaoGoodsList(paramMap);
		return list;
	}

	public List<TAbbGoods> searchHuigouGoodsList(String kinds,String address,String condition,int page){
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("condition",condition);
		paramMap.put("address",address);
		paramMap.put("page",page);
		paramMap.put("kinds",kinds);
		List<TAbbGoods> list = tAbbGoodsMapper.searchHuigouGoodsList(paramMap);
		return list;
	}


	public List<TAbbGoods> getQianggouGoodsList(String address,int page){
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("address",address);
		paramMap.put("page",page);
		List<TAbbGoods> list = tAbbGoodsMapper.getQianggouGoodsList(paramMap);
		return list;
	}


	public List<TAbbGoods> getMeishiGoodsList(String address,int page){
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("address",address);
		paramMap.put("page",page);
		List<TAbbGoods> list = tAbbGoodsMapper.getMeishiGoodsList(paramMap);
		return list;
	}

	public List<TAbbRenzheng> getShopList(String kinds,String address,int page){
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("address",address);
		paramMap.put("page",page);
		paramMap.put("kinds",kinds);
		List<TAbbRenzheng> list = tAbbRenzhengMapper.getShopList(paramMap);
		return list;
	}

	public List<TAbbGoods> getHuigouGoodsByShopId(String shopid,int page){
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("page",page);
		paramMap.put("shopid",shopid);
		List<TAbbGoods> list = tAbbGoodsMapper.getHuigouGoodsByShopId(paramMap);
		return list;
	}

	public void updateYuliu3ByType(Integer type) {
		tAbbGoodsMapper.updateYuliu3ByType(type);
	}
	public Map<String,Object> getRecommendGoods(int type){
		Map<String,Object> resMap = new HashMap<>();
		Map<String,Object> paramMap = new HashMap<>();
		paramMap.put("type",type);
		TAbbGoods tAbbGoods = tAbbGoodsMapper.getRecommendGoods(paramMap);
		if(null!=tAbbGoods){
			resMap.put("success",true);
			resMap.put("tAbbGoods",tAbbGoods);
			resMap.put("flag","1");
			resMap.put("msg","获取推荐商品成功");
		}else{
			resMap.put("success",true);
			resMap.put("flag","0");
			resMap.put("msg","没有推荐商品");
		}
		return  resMap;
	}

}
